package com.nlp.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nlp.utils.SendMessage;

@RestController
@RequestMapping(value = "/sentimentController")
public class SentimentController {

	private static String zhUrl = "http://120.92.213.99:8080/zh";
	private static String enUrl = "http://120.92.213.99:8080/en";
	
//	private static String zhUrl = "http://10.0.2.13:8002/zh";
//	private static String enUrl = "http://10.0.2.13:8022/en";

	@RequestMapping(value = "/getSentiment", method = RequestMethod.POST)
	public String getSentiment(@RequestBody Map<String, String> parms) {

		String language = parms.get("language");
		ObjectMapper mapper = new ObjectMapper();
		String writeValueAsString;
		try {
			writeValueAsString = mapper.writeValueAsString(parms);
			if ("zh".equals(language))
				return SendMessage.translateByPost(zhUrl, writeValueAsString);
			if ("en".equals(language))
				return SendMessage.translateByPost(enUrl, writeValueAsString);
			return "参数有误";
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}

		return "错误";
//		return "{\"message\":\"Success\",\"data\":[{\"score\":-1200000}],\"result\":0}";
	}

//	public static void main(String[] args) {
//		SentimentController controller = new SentimentController();
//		Map<String, String> parms = Maps.newHashMap();
//		parms.put("language", "zh");
//		parms.put("text", "I am very sad and being unemployed produces negative attitudes to work");
//		String sentiment = controller.getSentiment(parms);
//		System.out.println(sentiment);
//	}
}
